#include <stdio.h>

void length()
{
 /*80484d0:	55                   	push   %ebp
 80484d1:	89 e5                	mov    %esp,%ebp
 80484d3:	83 ec 38             	sub    $0x38,%esp
 80484d6:	c7 44 24 04 14 00 00 	movl   $0x14,0x4(%esp)	// 20 ---> 5指针，因每个指针占4个字节 (32bit系统)
 80484dd:	00 
 80484de:	c7 04 24 d4 86 04 08 	movl   $0x80486d4,(%esp)
 80484e5:	e8 a6 fe ff ff       	call   8048390 <printf@plt>*/
 printf("sizeof(*pa[5]) = %d\n", 20); 

 /*80484ea:	c7 44 24 04 04 00 00 	movl   $0x4,0x4(%esp)	// 4 ---> 1个指针，占4字节 (32bit系统)
 80484f1:	00 
 80484f2:	c7 04 24 ea 86 04 08 	movl   $0x80486ea,(%esp)
 80484f9:	e8 92 fe ff ff       	call   8048390 <printf@plt>*/
 printf("sizeof((*ptr)[5]) = %d\n", 4);

 /*80484fe:	c9                   	leave  
 80484ff:	c3                   	ret  */
}    

void pointer_array()
{
 /*8048500:	55                   	push   %ebp
 8048501:	89 e5                	mov    %esp,%ebp
 8048503:	83 ec 48             	sub    $0x48,%esp
 8048506:	c7 45 d0 01 00 00 00 	movl   $0x1,-0x30(%ebp)
 804850d:	c7 45 d4 02 00 00 00 	movl   $0x2,-0x2c(%ebp)
 8048514:	c7 45 d8 03 00 00 00 	movl   $0x3,-0x28(%ebp)
 804851b:	c7 45 dc 04 00 00 00 	movl   $0x4,-0x24(%ebp)
 8048522:	c7 45 e0 05 00 00 00 	movl   $0x5,-0x20(%ebp)
 8048529:	c7 45 e4 06 00 00 00 	movl   $0x6,-0x1c(%ebp)
 8048530:	c7 45 e8 07 00 00 00 	movl   $0x7,-0x18(%ebp)
 8048537:	c7 45 ec 08 00 00 00 	movl   $0x8,-0x14(%ebp)
 804853e:	c7 45 f0 09 00 00 00 	movl   $0x9,-0x10(%ebp)*/
 int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

 /*8048545:	8d 45 d0             	lea    -0x30(%ebp),%eax
 8048548:	89 45 f4             	mov    %eax,-0xc(%ebp)*/
 int (*ptr)[3] = a;

 /*804854b:	8b 45 f4             	mov    -0xc(%ebp),%eax	// eax=ptr --> 1
 804854e:	8b 50 08             	mov    0x8(%eax),%edx	// edx=ptr+8 --> 3
 8048551:	8b 45 f4             	mov    -0xc(%ebp),%eax	// eax=ptr
 8048554:	8b 40 04             	mov    0x4(%eax),%eax	// eax=ptr+4 --> 2
 8048557:	89 54 24 08          	mov    %edx,0x8(%esp)
 804855b:	89 44 24 04          	mov    %eax,0x4(%esp)
 804855f:	c7 04 24 03 87 04 08 	movl   $0x8048703,(%esp)
 8048566:	e8 25 fe ff ff       	call   8048390 <printf@plt>*/
 printf("%d %d\n", (*ptr)[1], (*ptr)[2]);    // 2    3

 /*804856b:	83 45 f4 0c          	addl   $0xc,-0xc(%ebp)*/	// (ebp-0xc)+=0xc 
 ++ptr;

 /*804856f:	8b 45 f4             	mov    -0xc(%ebp),%eax		// eax=ptr --> 4
 8048572:	8b 50 08             	mov    0x8(%eax),%edx		// edx=ptr+8 ---> 6
 8048575:	8b 45 f4             	mov    -0xc(%ebp),%eax		// eax=ptr
 8048578:	8b 40 04             	mov    0x4(%eax),%eax		// eax=ptr+4 ---> 5
 804857b:	89 54 24 08          	mov    %edx,0x8(%esp)
 804857f:	89 44 24 04          	mov    %eax,0x4(%esp)
 8048583:	c7 04 24 03 87 04 08 	movl   $0x8048703,(%esp)
 804858a:	e8 01 fe ff ff       	call   8048390 <printf@plt>*/
 printf("%d %d\n", (*ptr)[1], (*ptr)[2]);    // 5    6

 /*804858f:	c9                   	leave  
 8048590:	c3                   	ret  */
}

void array_pointer()
{
 /*8048591:	55                   	push   %ebp
 8048592:	89 e5                	mov    %esp,%ebp
 8048594:	83 ec 58             	sub    $0x58,%esp
 8048597:	c7 45 d0 01 00 00 00 	movl   $0x1,-0x30(%ebp)
 804859e:	c7 45 d4 02 00 00 00 	movl   $0x2,-0x2c(%ebp)
 80485a5:	c7 45 d8 03 00 00 00 	movl   $0x3,-0x28(%ebp)
 80485ac:	c7 45 dc 04 00 00 00 	movl   $0x4,-0x24(%ebp)
 80485b3:	c7 45 e0 05 00 00 00 	movl   $0x5,-0x20(%ebp)
 80485ba:	c7 45 e4 06 00 00 00 	movl   $0x6,-0x1c(%ebp)
 80485c1:	c7 45 e8 07 00 00 00 	movl   $0x7,-0x18(%ebp)
 80485c8:	c7 45 ec 08 00 00 00 	movl   $0x8,-0x14(%ebp)
 80485cf:	c7 45 f0 09 00 00 00 	movl   $0x9,-0x10(%ebp)*/
 int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

 int *pa[3];
 /*80485d6:	8d 45 d0             	lea    -0x30(%ebp),%eax		// eax=pa
 80485d9:	89 45 c4             	mov    %eax,-0x3c(%ebp)*/	// 第一个指针
 pa[0] = a[0];	// 1

 /*80485dc:	8d 45 d0             	lea    -0x30(%ebp),%eax		// eax=pa
 80485df:	83 c0 0c             	add    $0xc,%eax			// eax=eax+0xc
 80485e2:	89 45 c8             	mov    %eax,-0x38(%ebp)*/	// 第二个指针
 pa[1] = a[1];	// 4

 /*80485e5:	8d 45 d0             	lea    -0x30(%ebp),%eax		// eax=pa
 80485e8:	83 c0 18             	add    $0x18,%eax			// eax=eax+0x18
 80485eb:	89 45 cc             	mov    %eax,-0x34(%ebp)*/	// 第三个指针
 pa[2] = a[2];	// 7

 /*80485ee:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)*/
 int i = 0;

 /*80485f5:	eb 1d                	jmp    8048614 <array_pointer+0x83>
 80485f7:	8b 45 f4             	mov    -0xc(%ebp),%eax			// eax=i
 80485fa:	8b 44 85 c4          	mov    -0x3c(%ebp,%eax,4),%eax	// eax=(ebp+i*4)-0x3c --> pa[0],pa[1],pa[2]
 80485fe:	8b 00                	mov    (%eax),%eax				// eax=(pa[i])
 8048600:	89 44 24 04          	mov    %eax,0x4(%esp)			// (esp+0x4)=eax
 8048604:	c7 04 24 0a 87 04 08 	movl   $0x804870a,(%esp)
 804860b:	e8 80 fd ff ff       	call   8048390 <printf@plt>
 8048610:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)			// i+1
 8048614:	83 7d f4 02          	cmpl   $0x2,-0xc(%ebp)			// 2?=i
 8048618:	7e dd                	jle    80485f7 <array_pointer+0x66>*/
 for(i = 0; i < 3; i++)
     printf("%d ", *pa[i]);		// 1 4 7

 /*804861a:	c9                   	leave  
 804861b:	c3                   	ret */
}   

int main()
{
 /*804861c:	55                   	push   %ebp
 804861d:	89 e5                	mov    %esp,%ebp
 804861f:	83 e4 f0             	and    $0xfffffff0,%esp
 8048622:	e8 a9 fe ff ff       	call   80484d0 <length>*/
 length();

 /*8048627:	e8 d4 fe ff ff       	call   8048500 <pointer_array>*/
 pointer_array();

 /*804862c:	e8 60 ff ff ff       	call   8048591 <array_pointer>*/
 array_pointer();

 /*8048631:	c9                   	leave  
 8048632:	c3                   	ret    
 8048633:	66 90                	xchg   %ax,%ax
 8048635:	66 90                	xchg   %ax,%ax
 8048637:	66 90                	xchg   %ax,%ax
 8048639:	66 90                	xchg   %ax,%ax
 804863b:	66 90                	xchg   %ax,%ax
 804863d:	66 90                	xchg   %ax,%ax
 804863f:	90                   	nop*/
 return 0;
}
